package HandleXml.model;

import javax.xml.bind.annotation.*;

@XmlAccessorType(XmlAccessType.FIELD)
public class Book {
    @XmlAttribute
    private String id;
    @XmlAttribute
    private String category;
    @XmlElement
    private Title title;
    @XmlElement
    private Author author;
    @XmlElement(namespace = "http://www.publisher.org")
    private Publisher publisher;
    @XmlElement
    private String description;
    @XmlElement
    private Price price;
    @XmlAttribute(name = "currency")
    private String currency;
    @XmlElement
    private String pubdate;

    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Price {
        @XmlValue
        private double value;
        @XmlAttribute
        private String currency;

        public double getValue() { return value; }
        public void setValue(double value) { this.value = value; }
        public String getCurrency() { return currency; }
        public void setCurrency(String currency) { this.currency = currency; }
    }
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Title {
        @XmlValue
        private String value;
        @XmlAttribute
        private String lang;

        public String getValue() { return value; }
        public void setValue(String value) { this.value = value; }
        public String getLang() { return lang; }
        public void setLang(String lang) { this.lang = lang; }

        @Override
        public String toString() {
            return "Title{" +
                    "value='" + value + '\'' +
                    ", lang='" + lang + '\'' +
                    '}';
        }
    }

    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Author {
        @XmlElement
        private String name;
        @XmlElement
        private String nationality;
        @XmlElement
        private String email;

        public String getName() { return name; }
        public void setName(String name) { this.name = name; }
        public String getNationality() { return nationality; }
        public void setNationality(String nationality) { this.nationality = nationality; }
        public String getEmail() { return email; }
        public void setEmail(String email) { this.email = email; }

        @Override
        public String toString() {
            return "Author{" +
                    "name='" + name + '\'' +
                    ", nationality='" + nationality + '\'' +
                    ", email='" + email + '\'' +
                    '}';
        }
    }

    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Publisher {
        @XmlElement(namespace = "http://www.publisher.org")
        private String name;
        @XmlElement(namespace = "http://www.publisher.org")
        private String address;

        public String getName() { return name; }
        public void setName(String name) { this.name = name; }
        public String getAddress() { return address; }
        public void setAddress(String address) { this.address = address; }

        @Override
        public String toString() {
            return "Publisher{" +
                    "name='" + name + '\'' +
                    ", address='" + address + '\'' +
                    '}';
        }
    }

    // Getters and Setters
    public String getId() { return id; }
    public void setId(String id) { this.id = id; }
    public String getCategory() { return category; }
    public void setCategory(String category) { this.category = category; }
    public Title getTitle() { return title; }
    public void setTitle(Title title) { this.title = title; }
    public Author getAuthor() { return author; }
    public void setAuthor(Author author) { this.author = author; }
    public Publisher getPublisher() { return publisher; }
    public void setPublisher(Publisher publisher) { this.publisher = publisher; }
    public String getDescription() { return description; }
    public void setDescription(String description) { this.description = description; }
    public Price getPrice() { return price; }
    public void setPrice(Price price) { this.price = price; }
    public String getCurrency() { return currency; }
    public void setCurrency(String currency) { this.currency = currency; }
    public String getPubdate() { return pubdate; }
    public void setPubdate(String pubdate) { this.pubdate = pubdate; }

    @Override
    public String toString() {
        return "Book{" +
                "id='" + id + '\'' +
                ", category='" + category + '\'' +
                ", title=" + title +
                ", author=" + author +
                ", publisher=" + publisher +
                ", description='" + description + '\'' +
                ", price=" + price +
                ", currency='" + currency + '\'' +
                ", pubdate='" + pubdate + '\'' +
                '}';
    }
}